﻿Imports ExImageResizer
Imports System.IO


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        If FileUpload1.HasFile Then

            Dim ir As New ExImage

            ir.ResizeFromStream(Path.Combine( _
                HttpContext.Current.Request.PhysicalApplicationPath, _
                Path.GetFileName(FileUpload1.FileName)), 200, 200, _
                    FileUpload1.PostedFile.InputStream)
            Image1.ImageUrl = Path.Combine(WebRoot, FileUpload1.FileName)
            Image1.Visible = True

        End If
    End Sub

    Public Shared ReadOnly Property WebRoot() As String
        Get
            Dim ctx As HttpContext = HttpContext.Current
            If ctx.Request.ApplicationPath = "/" Then
                Return String.Format("{0}://{1}/", _
                    ctx.Request.Url.Scheme, ctx.Request.Url.Authority)
            Else
                Return String.Format("{0}://{1}{2}/", _
                    ctx.Request.Url.Scheme, ctx.Request.Url.Authority, ctx.Request.ApplicationPath)
            End If
        End Get
    End Property


End Class
